//-----------------------------------------------------------------------
// <copyright file="DeleteVirtualDirectory.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <author>Mark Phillips</author>
// <email>andyr</email>
// <date>2004-03-23</date>
// <summary>Deletes the specfied Virtual Directory.</summary>
//-----------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks.Web.FtpSite
{
    using System;
    using System.Xml;
    using System.Globalization;
    using Microsoft.Sdc.Tasks.Configuration.Web;
    using Microsoft.Build.Framework;

    /// <summary>
    /// Deletes an ftp virtual directory 
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[<Web.FtpSite.DeleteVirtualDirectory 
    ///     VirtualDirectoryName="virtualDirectoryName" 
    ///     FtpSiteName="ftpSiteName"
    ///     MachineName="machineName">]]></code>
    /// <para>where:</para>
    /// <para><i>virtualDirectoryName (Required)</i></para>
    /// <para>A valid virtual directory name</para>
    /// <para><i>machineName</i></para>
    /// <para>Machine to delete the virtual directory from. If unspecified the action will execute against the local machine.</para>
    /// <para><i>ftpSiteName</i></para>
    /// <para>The FTP site to delete the virtual directory from</para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///         <Web.FtpSite.DeleteVirtualDirectory VirtualDirectoryName="/virtual" />
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>    
    public class DeleteVirtualDirectory : TaskBase
    {
        private string name = String.Empty;
        private string machineName = String.Empty;
        private string ftpSiteName = String.Empty;

        /// <summary>
        /// Initializes a new instance of the DeleteFtpVirtualDirectory class.
        /// </summary>
        public DeleteVirtualDirectory()
        {
        }

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            #region Execute code

            FtpSite ftp;
            FtpVirtualDirectory vdir;

            if (ftpSiteName.Length == 0)
            {
                ftpSiteName = "Default FTP Site";
            }

            if (machineName.Length == 0)
            {
                machineName = "localhost";
            }

            ftp = FtpSite.Load(machineName, ftpSiteName);
            vdir = ftp.VirtualDirectories[name];
            if (vdir != null)
            {
                Log.LogMessageFromResources("Web.DeleteVirtualDirectory", name);
                //vdir.AppDelete();
                vdir.Delete();
            }

            #endregion
        }

        /// <summary>
        /// Name of the virtual directory to delete
        /// </summary>
        /// <value>any valid directory name</value>
        [Required]
        public string VirtualDirectoryName
        {
            get
            {
                return (name == null ? String.Empty : name);
            }
            set
            {
                name = value;
            }
        }

        /// <summary>
        /// Machine name to delete the virtual directory from
        /// </summary>
        /// <value>A valid machine name. 
        /// If unspecified the action will execute against the local machine</value>
        public string MachineName
        {
            get
            {
                return (machineName == null ? String.Empty : machineName);
            }
            set
            {
                machineName = value;
            }
        }

        /// <summary>
        /// FTP site to delete the virtual directory from
        /// </summary>
        /// <value>A valid, existing FTP site name</value>
        public string FtpSiteName
        {
            get
            {
                return (ftpSiteName == null ? String.Empty : ftpSiteName);
            }
            set
            {
                ftpSiteName = value;
            }
        }
    }
}

